//
//  GRBuyMsgTableViewCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/8/27.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRBuyMsgTableViewCell.h"
#import "GRBuyRuleCell.h"
@implementation GRBuyMsgTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.ruleList.dataSource = self;
    self.ruleList.delegate = self;
    [self.ruleList registerNib:[UINib nibWithNibName:@"GRBuyRuleCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GRBuyRuleCell"];
}
-(void)updateWithModel:(id)model atIndexPath:(NSIndexPath *)indexPath inView:(UIView *)view{
    self.ruleModel = model;
    self.leftOffset.constant = 10;
    self.rightOffset.constant = 10;
    [self.ruleList reloadData ];
    
    
}

-(void)setRuleModel:(GRGoodDetailMsgModel *)ruleModel{
    _ruleModel = ruleModel;
    self.titleLabel.text = ruleModel.title;
    [self.ruleList reloadData];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GRBuyRuleCell * buyRuleCell = [tableView dequeueReusableCellWithIdentifier:@"GRBuyRuleCell" forIndexPath:indexPath];
    buyRuleCell.contentLabel.text = self.ruleModel.items[indexPath.row];
    return buyRuleCell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.ruleModel.items.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [GRBuyRuleCell getHeightWiht:self.ruleModel.items[indexPath.row]];
}

+(CGFloat)getCellHeightWithModel:(GRGoodDetailMsgModel *)mode{
    CGFloat heigth = 35;
    for (NSString * content in mode.items) {
        heigth +=   [content boundingRectWithSize:CGSizeMake(KscreenWidth-60, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height+5;
    }
    return heigth;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
